package com.zh.note.huawei.onehundred.五键盘的输出;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/9/4 10:13
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String line = sc.nextLine();
        String line = "1 1 5 1 5 2 4 4";
        String[] strs = line.split(" ");
        StringBuilder screen = new StringBuilder();
        String select = "";//选中的
        String copy = ""; // 粘贴板
        for (String op : strs) {
            switch (op) {
                case "1"://将当前选中的字符串清空，然后在字符串末尾添加A
                    select = clear(screen, select);
                    screen.append("A");
                    break;
                case "2": // 将当前选中的字符串复制给粘贴板
                    copy = !select.isEmpty() ? select : copy;
                    break;
                case "3": //将当前选中的字符清空，并将剪贴版清空
                    if (!select.isEmpty()) {
                        copy = select;
                        screen = new StringBuilder();
                    }
                    break;
                case "4": //将当前选中的字符串清空，并将粘贴板的字符串添加的字符串末尾
                    select = clear(screen, select);
                    screen.append(copy);
                    break;
                case "5": //全选
                    select = screen.length() != 0 ? screen.toString() : select;
                    break;
                default:
                    break;
            }

        }
        System.out.println(screen.length());
    }

    private static String clear(StringBuilder sb, String select) {
        if (!select.isEmpty()) {
            sb.replace(0, select.length(), "");
            select = "";
        }
        return select;
    }
}
